﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference path="Gammar.Price.PriceEntity.js" />
/// <author name="Argo Zhang" msn="Argo@live.ca" />

Type.registerNamespace("Gammar.Price.Web");

Gammar.Price.Web.Navigation = function(element) {
    Gammar.Price.Web.Navigation.initializeBase(this, [element]);
    this._displaySpan = null;
    this._pageEntityComponent = null;
}

Gammar.Price.Web.Navigation.prototype = {
    initialize: function() {
        Gammar.Price.Web.Navigation.callBaseMethod(this, 'initialize');
        
        // Add custom initialization here
        var element = this.get_element();
        var ac = element.getElementsByTagName("A");
        for(var i = 0; i< ac.length; i++) {
            $addHandler(ac[i], "click", Function.createDelegate(this, this._onClick));
        }
    },
    
    get_displaySpan: function() {
        /// <summary></summary>
        if (arguments.length !== 0) throw Error.parameterCount();         
        return this._displaySpan;
    },
    
    set_displaySpan: function(value) {
        /// <param name="value" type="domElement" />
        var e = Function._validateParams(arguments, [
            {name: "value", domElement : true}
        ]);
        if (e) throw e;
        
        this._displaySpan = value;
    },
    
    get_itemPanel: function() {
        /// <summary></summary>
        if (arguments.length !== 0) throw Error.parameterCount();         
        return this._itemPanel;
    },
    
    set_itemPanel: function(value) {
        /// <param name="value" type="String" />
        var e = Function._validateParams(arguments, [
            {name: "value", type : String}
        ]);
        if (e) throw e;
        
        this._itemPanel = value;
    },    
        
    _onClick: function(eventObject) {
        var span = this.get_displaySpan();
        if (span === null) return;
        
        var link = eventObject.target;
        span.innerHTML = link.title;
        
        var categoryList = $get(this.get_itemPanel());
        if (categoryList !== null) 
            categoryList.innerHTML = "";
        
        var itemPanel = $find(this.get_itemPanel());
        if (itemPanel !== null && itemPanel.updated != null) {
            itemPanel.updated(link.getAttribute("guid"));
        }
        
        var handler = this.get_events().getHandler("navigationClick");
        if (handler) handler(eventObject);
    },

    add_navigationClick: function(handler) {
        /// <summary></summary>
        /// <param name="handler" type="Function" />
        var e = Function._validateParams(arguments, [
            {name: "handler", type: Function}
        ]);
        if (e) throw e;        
        this.get_events().addHandler("navigationClick", handler);
    },
    
    remove_navigationClick: function(handler) {
        /// <summary></summary>
        /// <param name="handler" type="Function" />
        this.get_events().removeHandler("navigationClick", handler);
    },    

    dispose: function() {        
        //Add custom dispose actions here
        Gammar.Price.Web.Navigation.callBaseMethod(this, 'dispose');
    }
}
Gammar.Price.Web.Navigation.registerClass('Gammar.Price.Web.Navigation', Sys.UI.Behavior);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
